package service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import dao.AccountDAO;
import dao.BusinessDAO;
import dao.CustomeDAO;
import dao.ManagerDAO;
import dao.OrderDAO;
import po.Account;
import po.Business;
import po.Customer;
import po.Order;
import service.IManager;
@Service("imanager")
public class IManagerImpl implements IManager {
	@Autowired(required=true)
	private ManagerDAO md;
	@Autowired(required=true)
	private BusinessDAO bd;
	@Autowired(required=true)
	private AccountDAO ad;
	@Autowired(required=true)
	private CustomeDAO cud;
	
	@Override
	public  List<Customer> queryCustomers(String cid) {
		// TODO Auto-generated method stub
		if(cid==null){
			return md.listCustomers();
		}else{
			return md.listCustomersByCid(cid);
		}
	}

	@Transactional
	@Override
	public int queryGoods(String bID) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Transactional
	@Override
	public int verify(Business bus) {
		// TODO Auto-generated method stub
		bd.addBusiness(bus);
		ad.addAccount(bus.getAcc());
		return 0;
	}

	@Override
	public int pullOff(String[] ids) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int closeShop(String bID) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int signUp(Account acc) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public List<Business> queryBusinesses(String bid) {
		// TODO Auto-generated method stub
		if(bid==null){
			return md.listBusinesses();
		}else{
			return md.listBusinessesByBid(bid);
		}
	}

	@Override
	public List<Order> queryOrders(String oid) {
		// TODO Auto-generated method stub
		
		if(oid==null){
			return md.listOrders();
		}else{
			return md.listOrdersByOid(oid);
		}
	}

	@Transactional
	@Override
	public int addCustomer(Customer cm) {
		// TODO Auto-generated method stub
		cud.addCustomer(cm);
		ad.addAccount(cm.getAcc());
		return 0;
	}

}
